﻿using smcrypto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Encalgorithm
{
    public class Sm4Helper
    {
        public static string Encrypt_ECB(string decData, string key, bool hexString = true, bool isPadding = true)
        {
            if (string.IsNullOrEmpty(decData))
            {
                return "";
            }
            SM4Utils sM4Utils = new SM4Utils();
            sM4Utils.hexString = hexString;
            sM4Utils.isPadding = isPadding;
            sM4Utils.secretKey = key;
            string enc = sM4Utils.Encrypt_ECB(decData);
            return enc;
        }

        public static byte[] Encrypt_ECB(byte[] decData, string key, bool hexString = true, bool isPadding = true)
        {
            if (decData is null || decData.Length == 0)
            {
                return decData;
            }
            SM4Utils sM4Utils = new SM4Utils();
            sM4Utils.hexString = hexString;
            sM4Utils.isPadding = isPadding;
            sM4Utils.secretKey = key;
            return sM4Utils.Encrypt_ECB(decData);
        }



        public static string Decrypt_ECB(string encData, string key, bool hexString = true, bool isPadding = true)
        {

            if (string.IsNullOrEmpty(encData))
            {
                return "";
            }
            SM4Utils sM4Utils = new SM4Utils();
            sM4Utils.hexString = hexString;
            sM4Utils.isPadding = isPadding;
            sM4Utils.secretKey = key;
            string dec = sM4Utils.Decrypt_ECB(encData);
            return dec;
        }

        public static byte[] Deccrypt_ECB(byte[] encData, string key, bool hexString = true, bool isPadding = true)
        {
            if (encData is null || encData.Length == 0)
            {
                return encData;
            }
            SM4Utils sM4Utils = new SM4Utils();
            sM4Utils.hexString = hexString;
            sM4Utils.isPadding = isPadding;
            sM4Utils.secretKey = key;
            return sM4Utils.Decryp_ECB(encData);
        }

    }
}
